package com.ruoyi.supplier.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supplier.domain.TbRegion;
import com.ruoyi.supplier.service.ITbRegionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行政区域Controller
 * 
 * @author ruoyi
 * @date 2021-03-02
 */
@RestController
@RequestMapping("/supplier/region")
public class TbRegionController extends BaseController
{
    @Autowired
    private ITbRegionService tbRegionService;

    /**
     * 查询行政区域列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbRegion tbRegion)
    {
        startPage();
        List<TbRegion> list = tbRegionService.selectTbRegionList(tbRegion);
        return getDataTable(list);
    }

    /**
     * 导出行政区域列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:region:export')")
    @Log(title = "行政区域", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbRegion tbRegion)
    {
        List<TbRegion> list = tbRegionService.selectTbRegionList(tbRegion);
        ExcelUtil<TbRegion> util = new ExcelUtil<TbRegion>(TbRegion.class);
        return util.exportExcel(list, "region");
    }

    /**
     * 获取行政区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbRegionService.selectTbRegionById(id));
    }

    /**
     * 新增行政区域
     */
    @PreAuthorize("@ss.hasPermi('supplier:region:add')")
    @Log(title = "行政区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRegion tbRegion)
    {
        return toAjax(tbRegionService.insertTbRegion(tbRegion));
    }

    /**
     * 修改行政区域
     */
    @PreAuthorize("@ss.hasPermi('supplier:region:edit')")
    @Log(title = "行政区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRegion tbRegion)
    {
        return toAjax(tbRegionService.updateTbRegion(tbRegion));
    }

    /**
     * 删除行政区域
     */
    @PreAuthorize("@ss.hasPermi('supplier:region:remove')")
    @Log(title = "行政区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbRegionService.deleteTbRegionByIds(ids));
    }
}
